package com.byit.Test.Mytest1.ProducerAndConsumer;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @ClassName Main
 * @Description TODO
 * @Author lxp
 * @Date 2018/10/9 0009
 **/
public class Main {

    public static void main(String[] args) {
        //定义一个仓库,消费者和生产者都使用这一个仓库
        Repertory repertory=new Repertory();
        //定义三个生产者(p1,p2,p3)
        Producer p1=new Producer(repertory);
        Producer p2=new Producer(repertory);
        //定义两个消费者(c1,c2)
        Consumer c1=new Consumer(repertory);
        Consumer c2=new Consumer(repertory);
        Consumer c3=new Consumer(repertory);
        Consumer c4=new Consumer(repertory);
        //定义5个线程(t1,t2,t3,t4,t5)
        Thread t1=new Thread(p1,"张飞");
        Thread t2=new Thread(p2,"赵云");
        Thread t3=new Thread(c1,"c1");
        Thread t4=new Thread(c2,"c2");
        Thread t5=new Thread(c3,"c3");
        Thread t6=new Thread(c4,"c4");


        ThreadPoolExecutor executor = new ThreadPoolExecutor(3, 10, 200, TimeUnit.MILLISECONDS,
                new ArrayBlockingQueue<Runnable>(5));

        //因为关羽跟赵云的生产积极性高,所以把他们的线程优先级调高一点
        t2.setPriority(10);
        t4.setPriority(10);
        executor.execute(t1);
        executor.execute(t2);
        executor.execute(t3);
        executor.execute(t4);
        executor.execute(t5);
        executor.execute(t6);

        System.out.println("线程池中线程数目："+executor.getPoolSize()+"，队列中等待执行的任务数目："+
                executor.getQueue().size()+"，已执行玩别的任务数目："+executor.getCompletedTaskCount());
        //启动线程
       /* t1.start();
        t2.start();
        t3.start();
        t4.start();
        t5.start();*/
    }
}
